<?php

namespace App\Services;



use App\Models\PhoneSetting;
use App\Models\SipUser;
use App\Models\Task;
use Illuminate\Support\Facades\Auth;

class BalanceService
{
    protected $sipUser;

    public function __construct(SipUser $sipUser)
    {
        $this->sipUser = $sipUser;
    }
    //周期更新si'p账号余额
    public function syncBalance(){
      $phone_settings = PhoneSetting::where([
          ['type','=','sip']
      ])->get();
      if($phone_settings){
            foreach ($phone_settings as $phone_setting){
                $res = $this->sipUser->where([
                    ['sip','=',$phone_setting->account],
                    ['pass','=',$phone_setting->auth_token]
                ])->first();
                if($res){
                    $phone_setting->update(['balance'=>$res->balance]);
                }
            }
      }
    }
}